﻿/*--------------------------------------------------
 Creater：Junxuan.Su
 Time：2014-1-3 14:55:25
 Remark : Zip
--------------------------------------------------*/

using System;
using System.IO;
using Ionic.Zip;

namespace HXDNB.Infrastructure.Helper
{
    public static class Zip
    {
        /// <summary>
        /// 压缩文件夹
        /// </summary>
        public static bool ZipDir(string path)
        {
            try
            {
                if (!Directory.Exists(path)) return false;

                using (var zip = new ZipFile())
                {
                    path = path.TrimEnd('/');
                    zip.AddDirectory(path);
                    zip.Save(path + ".zip");
                }

                return true;
            }
            catch (Exception ex)
            {
                Log.Error("Zip.ZipDir", ex.Message + ex.StackTrace);
                return false;
            }
        }
    }
}
